home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / FIX_DESK / SOURCE / BUNDLES.C < prev    next >
C/C++ Source or Header  |  1988-09-07  |  3KB  |  155 lines

  1. #include <MacTypes.h>
  2. #include <ResourceMgr.h>
  3.  
  4. #include "fix.h"
  5.  
  6.     /* Local types. */
  7.  
  8. typedef struct bndl_node {
  9.     struct bndl_node *next;
  10.     int bndl_id;
  11.     long bndl_type;
  12.     Handle bndl_resource;
  13. } bndl_node, *bndl_ptr;
  14.  
  15. static bndl_ptr bndl_table;
  16.  
  17.     /* Local prototypes. */
  18.  
  19. long bundle_type(Handle hand);
  20. void insert_bndl(int number, Handle hand);
  21. void kill_related(long type, Handle hand);
  22.  
  23.     /* Insert an bundle record into the list. */
  24.  
  25. static void insert_bndl(number, hand)
  26.     int number;
  27.     Handle hand;
  28. {
  29.     register bndl_ptr temp = (bndl_ptr) NewPtr((long) sizeof(bndl_node));
  30.  
  31.     temp->next = bndl_table;                /* Insert at    */
  32.     temp->bndl_id = number;                    /* beginning of */
  33.     temp->bndl_type = bundle_type(hand);    /* list...      */
  34.     temp->bndl_resource = hand;
  35.     bndl_table = temp;
  36. }
  37.  
  38.     /* Remove a bundle record from the list. */
  39.  
  40. void remove_bndl(type)
  41.     register long type;
  42. {
  43.     register bndl_ptr temp, prev;
  44.  
  45.     temp = bndl_table;
  46.     prev = NIL;
  47.     while ((temp) && (temp->bndl_type != type)) {
  48.         prev = temp;
  49.         temp = temp->next;
  50.     }
  51.     if (temp) {            /* Found it... */
  52.         if (!prev)        /* Unlink from chain... */
  53.             bndl_table = temp->next;
  54.         else
  55.             prev->next = temp->next;
  56.         DisposPtr(temp);
  57.     }
  58. }
  59.  
  60.     /* Find the owner of a bundle. */
  61.  
  62. static long bundle_type(hand)
  63.     Handle hand;
  64. {
  65.     return (**((long **)hand));
  66. }
  67.  
  68.     /* Perform initial bundle processing. */
  69.  
  70. void pre_bundle_processing()
  71. {
  72.     register Handle hand;
  73.     register int i, count;
  74.     int number;
  75.     long blob;
  76.     char blob2[256];
  77.  
  78.         /* Empty the bundle list. */
  79.  
  80.     bndl_count = 0;
  81.     bndl_table = NIL;
  82.  
  83.         /* Insert all BNDL resources into the list. */
  84.  
  85.     count = Count1Resources('BNDL');    /* Insert all BNDL    */
  86.     for (i=1; i<=count; i++) {            /* resources into the */
  87.         hand = Get1IndResource('BNDL',i); /* list...          */
  88.         HNoPurge(hand);
  89.         GetResInfo(hand, &number, &blob, &blob2);
  90.         insert_bndl(number, hand);
  91.     }
  92. }
  93.  
  94.     /* Perform final bundle processing. */
  95.  
  96. void post_bundle_processing()
  97. {
  98.     register bndl_ptr temp, temp2;
  99.  
  100.         /* Kill all related resources, then each bundle. */
  101.  
  102.     temp = bndl_table;
  103.     while (temp) {
  104.         bndl_count++;
  105. #ifndef TEST_MODE
  106.         kill_related(temp->bndl_type, temp->bndl_resource);
  107.         RmveResource(temp->bndl_resource);
  108.         DisposHandle(temp->bndl_resource);
  109. #endif TEST_MODE
  110.         temp2 = temp;
  111.         temp = temp->next;
  112.         DisposPtr(temp2);
  113.     }
  114. }
  115.  
  116. #ifndef TEST_MODE
  117.  
  118.     /* Remove resources referred to by a bundle. */
  119.  
  120. static void kill_related(type, hand)
  121.     long type;
  122.     Handle hand;
  123. {
  124.     register int *bundle;    /* Pointer to bundle so far... */
  125.     register int res_id,    /* Resource ID number. */
  126.                  num_types,    /* Number of resource types. */
  127.                  num_this;    /* Number of resources of this type. */
  128.     register long this_type;    /* Type of these resources. */
  129.  
  130.     HLock(hand);
  131.     bundle = (int *) *hand;
  132.  
  133.     bundle += 2;    /* Skip to signature ID #. */
  134.     res_id = *(bundle++);
  135.     kill_resource(type, res_id);
  136.  
  137.     num_types = *(bundle++);
  138.     while (num_types >= 0) {    /* For each type... */
  139.         --num_types;
  140.         this_type = *((long *) bundle);    /* Get the type... */
  141.         bundle += 2;
  142.         num_this = *(bundle++);            /* Count of this type... */
  143.         while (num_this >= 0) {            /* For each resource...  */
  144.             --num_this;                    /* Skip local ID...      */
  145.             bundle++;                    /* Get res. ID...        */
  146.             res_id = *(bundle++);        /* and remove it!        */
  147.             kill_resource(this_type,res_id);
  148.         }
  149.     }
  150.  
  151.     HUnlock(hand);
  152. }
  153.  
  154. #endif TEST_MODE
  155.